/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package thinkinginjava.svn.reflection.proxy;

/**
 *
 * @author public_enemy
 */
class RealObject implements Interface {

    @Override
    public void doSomething() {
        System.out.println(System.currentTimeMillis());
        System.out.println("doSomething");
        System.out.println(System.currentTimeMillis());
    }

    @Override
    public void doSomethingElse(String arg) {
        System.out.println(System.currentTimeMillis());
        System.out.println("somethingElse " + arg);
        System.out.println(System.currentTimeMillis());
    }
}

class SimpleProxy implements Interface {

    private Interface proxied;

    public SimpleProxy(Interface proxied) {
        this.proxied = proxied;
    }

    @Override
    public void doSomething() {
        System.out.println("SimpleProxy doSomething");
        proxied.doSomething();
    }

    @Override
    public void doSomethingElse(String arg) {
        System.out.println("SimpleProxy somethingElse " + arg);
        proxied.doSomethingElse(arg);
    }
}

public class SimpleProxyDemo {

    public static void consumer(Interface iface) {
        iface.doSomething();
        iface.doSomethingElse("bonobo");
    }

    public static void main(String[] args) {
        consumer(new RealObject());
        consumer(new SimpleProxy(new RealObject()));
    }
}
